<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>骡窝窝门票中心</title>
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <link href="/cc/css/style.css" rel="stylesheet" type="text/css"/>
        <script type="text/javascript" src="/js/jquery/jquery.min.js"></script>
        <script type="text/javascript" src="/cc/js/tab.js"></script>
        <script src="/js/plugins/jrender/jrender.min.js"></script>
        <link href="/ticket/css/style.css" rel="stylesheet" type="text/css" />
        <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
        <script src="/js/plugins/dialog2/dialog.min.js"></script>

        <script type="text/javascript">
            $(function(){

                $(".aui-head-title").click(function(){
                    $(this).toggleClass("aui-current-up").siblings(".aui-head-title").removeClass("aui-current-up");
                    $(this).toggleClass("aui-current-tx").siblings(".aui-head-title").removeClass("aui-current-tx");
                    $(this).next(".aui-box-content").slideToggle(100).siblings(".aui-box-content").slideUp(400);
                });

                //查询是推荐状态的景点门票
                $.get("/regions/commendTicket/",{state:2},function (data) {

                    var num=1;

                    $(".commend").renderValues(data,{
                        indexFun:function (item, value) {
                            $(item).html("TOP"+num);
                            num++;
                        },
                        getHref1:function (item,value) {
                             var url= $(item).data("href");
                             $(item).attr("href",url+value)
                        },
                        cutFun:function (item,value) {
                            $(item).html(value+"折")
                        },
                        getRMB1:function (item,value) {
                            $(item).html("￥"+value)
                        }
                    });

                });

                //声明一个变量,用于当前页的增加
                var currentPage = 1;
                //总页数
                var pages;
                //存储游记的数组
                var ticketArr = [];
                //当点击上面的搜索的栏目的时候
                $("#queryFun").click(function () {
                    //查询所有的景点
                    //判断之前有没有拼接过
                    if ($("#span :last-child").val() == -1) {
                        $.get("/regions/getScenic", function (data) {
                            var temp = "";
                            $.each(data, function (index, ele) {
                                temp += '<option value="' + ele.id + '">' + ele.name + '</option>';
                            });
                            $("#span").append(temp);
                        });
                    }

                });

                //定义一个函数,函数里发请求,使得变量的值金有限于该次访问
                function query() {
                    //默认查询所有景点
                    $.get("/regions/commendTicket", {selected: -1, currentPage:currentPage}, function (data) {
                        console.log(data);
                        if (data.list.length > 0) {
                            var num = 1;
                            $.merge(ticketArr, data.list);
                            var json = {list: ticketArr};
                            $("#cccc").renderValues(json, {
                                indexFun: function (item, value) {
                                    $(item).html("TOP" + num);
                                    num++;
                                },
                                getHref2: function (item, value) {
                                    var url = $(item).data("href");
                                    $(item).attr("href", url + value)
                                },
                                cutFun: function (item, value) {
                                    $(item).html(value + "折")
                                },
                                getRMB2: function (item, value) {
                                    $(item).html("￥" + value)
                                }
                            });
                            //获取总页数
                            pages = data.pages;
                        }
                    });
                    //当前页加1
                    currentPage = currentPage + 1;

                }
                //执行函数
                query();
                //滚动事件
                $(window).scroll(function () {
                    if ($(window).height() + $(document).scrollTop() + 1 >= $(document).height()) {
                        if (currentPage <= pages) {
                            query();
                        } else {
                            $(document).dialog({
                                type: 'notice',
                                content: '<span class="info-text">已经到底了</span>',
                                autoClose: 2000
                            })
                        }
                    }
                });


                //高级查询，查找景点
                $("#query").click(function () {
                    var keyword=  $("#q").val();
                    var selected=  $("#span option:selected").val();

                        $.get("/regions/commendTicket", {keyword: keyword, selected: selected}, function (data) {
                            if (data.list.length > 0) {
                                console.log(data);

                                var num = 1;
                                $("#cccc").renderValues(data, {
                                    indexFun: function (item, value) {
                                        $(item).html("TOP" + num);
                                        num++;
                                    },
                                    getHref2: function (item, value) {
                                        var url = $(item).data("href");
                                        $(item).attr("href", url + value)
                                    },
                                    cutFun: function (item, value) {
                                        $(item).html(value + "折")
                                        var url = $(item).data("href");
                                    },
                                    getRMB2: function (item, value) {
                                        $(item).html("￥" + value)
                                    }
                                });

                            } else {
                                $(document).dialog({
                                    titleShow: false,
                                    content: "请输入要查找的景点"
                                });
                            }

                        });
                });

            })
        </script>

    </head>
    <body style="height: auto">

        <section class="aui-flexView">
            <header class="aui-navBar aui-navBar-fixed">
                <div >
                    <a href="/index.html;" class="aui-navBar-item">
                        <i class="icon icon-return"></i>
                    </a>
                </div>
                <div class="aui-center">
                    <span class="aui-center-title">骡窝窝门票</span>
                </div>
                <a href="javascript:;" class="aui-navBar-item">
                    <i class="icon icon-sys"></i>
                </a>
            </header>
            <section class="aui-scrollView">
                <div class="aui-ad-box" >
                    <img  style="height: 150px" src="upload/e6066b48-85ec-48c2-8c1d-4c2ed41fcacc.jpeg" alt="">
                </div>
                <div class="aui-tab" data-ydui-tab>
                    <ul class="tab-nav">
                        <li class="tab-nav-item tab-active">
                            <a href="javascript:;">热门推荐</a>
                        </li>
                        <li class="tab-nav-item">
                            <a  id="queryFun" href="javascript:;">搜索</a>
                        </li>
                    </ul>

                    <div class="tab-panel">
                        <div class="commend">
                        <div class="tab-panel-item tab-active" render-loop="list">

                            <div class="aui-spot-item">
                                <div class="aui-flex">
                                    <div class="aui-flex-spot-img">
                                        <img  render-src="list.coverUrl" alt="">
                                        <span class="aui-spot-tag" render-key="id" render-fun="indexFun"></span>
                                    </div>
                                    <div class="aui-flex-box">
                                        <h2 render-html="list.name"></h2>
                                        <p style="color: red">亲，走过路过别错过..... <a render-key="list.id" render-fun="getHref1" data-href="/mine/order.html?id=">点我买票--></a></p>
                                        <p render-key="list.cutoff" render-fun="cutFun"></p>
                                        <span class="aui-spot-pic">
                                        <em>今日有票</em>
                                       <em class="aui-spot-pic-red">门票</em>
                                            <p style="color: red" render-html="list.grade"></p>

                                    </span>
                                        <span class="aui-spot-price" render-fun="getRMB1" render-key="list.price"></span>
                                    </div>
                                </div>
                                <div class="aui-spot-gray" >
                                    <div class="aui-spot-gray-text">
                                        <p><em>简介: </em><br/><span render-html="list.intro"></span></p>
                                    </div>
                                </div>
                            </div>



                        </div>
                    </div>

                     <!--   搜索-->
                        <div class="tab-panel-item  selectedCommend">
                            <div class="search_box">
                                <span class="left l_bg"></span>
                                <span class="right r_bg"></span>
                                <div class="search">
                                    <form name=search_form onSubmit="return bottomForm(this);" target="_blank" method="post">
                                        <div id="pt1" class="select">
                                            <select style="border-style:none" class="c-select form-control" id="span" name="dept">
                                                <option value="-1">所有景点</option>
                                            </select>
                                        </div>
                                        <input id="catId" name="catId" type="hidden" value="7" />
                                        <input id="q" class="enter" name="keyword" placeholder="请输入要搜索的景点"/>
                                        <input id="query" class="sb" name="input" type="button" value="" />
                                    </form>
                                </div>
                            </div>


                            <div id="cccc" >


                            <div render-loop="list">

                            <div class="aui-spot-item">
                                <div class="aui-flex">
                                    <div class="aui-flex-spot-img">
                                        <img  render-src="list.coverUrl" alt="">
                                        <span class="aui-spot-tag" render-key="id" render-fun="indexFun"></span>
                                    </div>
                                    <div class="aui-flex-box">
                                        <h2 render-html="list.name"></h2>
                                        <p style="color: red">亲，走过路过别错过..... <a render-key="list.id" render-fun="getHref2" data-href="/mine/order.html?id=">点我买票--></a></p>
                                        <p render-key="list.cutoff" render-fun="cutFun"></p>
                                        <span class="aui-spot-pic">
                                        <em>今日有票</em>
                                       <em class="aui-spot-pic-red">门票</em>
                                            <p style="color: red" render-html="list.grade"></p>
                                    </span>
                                        <span class="aui-spot-price" render-fun="getRMB2" render-key="list.price"></span>
                                    </div>
                                </div>
                                <div class="aui-spot-gray" >
                                    <div class="aui-spot-gray-text">
                                        <p><em>简介: </em><br/><span render-html="list.intro"></span></p>
                                    </div>
                                </div>
                            </div>

                            </div>
                            </div>
                        </div>
                    </div>
                </div>
            </section>
        </section>
    </body>
</html>
